<?php

namespace App\Http\Models;

class SMSModel
{
	const SMS_URL = 'http://dove.cyou-inc.com/services/sendMessage';
	const SMS_USER_ID = 57;
	const SMS_BUSINESS_KEY = 'yingxiao';
	const SMS_KEY = 'kly^*rtrt9456()45656fgfg#656hgy';
	const SMS_CODE = '';

	protected static $sendMessages = array(
		"reset" => "[赢销+]您正在申请找回密码，验证码是：{verify_code}（30分钟内有效，如非本人操作请忽略，本条免费）。",
		"regist" => "[赢销+]您申请注册赢销+账号，验证码是：{verify_code}（30分钟内有效，如非本人操作请忽略，本条免费）。",
		"BindingMobile" => "[赢销+]您正在申请手机绑定，验证码是：{verify_code}（30分钟内有效，如非本人操作请忽略，本条免费）。",
		"VerifyMobile" => "[赢销+]您正在申请手机号码验证，验证码是：{verify_code}（30分钟内有效，如非本人操作请忽略，本条免费）。",
		"UnbundlingMobile" => "[赢销+]您正在申请修改绑定手机，验证码是：{verify_code}（30分钟内有效，如非本人操作请忽略，本条免费）。",
		"BindingEmail" => "[赢销+]您正在申请绑定邮箱，验证码是：{verify_code}（30分钟内有效，如非本人操作请忽略，本条免费）。",
		"UnbundlingEmail" => "[赢销+]您正在申请修改邮箱，验证码是：{verify_code}（30分钟内有效，如非本人操作请忽略，本条免费）。",
		"UpdatePwd" => "[赢销+]您正在申请重置赢销+平台密码，验证码是：{verify_code}（30分钟内有效，如非本人操作请忽略，本条免费）。"
	);

	public static function send($telephone, $type, $code = '000000')
	{
		$msg = isset(self::$sendMessages[$type]) ? self::$sendMessages[$type] : '';
		
		if(empty($msg))return false;

		$msg = str_replace('{verify_code}', $code, $msg);

		$timestamp = date("YmdHis",time());
		$validate = MD5( self::SMS_KEY . MD5( self::SMS_USER_ID . $telephone . self::SMS_BUSINESS_KEY  . self::SMS_KEY));
		$msg = urlencode($msg);
		$requires_url = "http://dove.cyou-inc.com/services/sendMessage?userid=".self::SMS_USER_ID."&telephone=".$telephone."&msg=".$msg."&code=".self::SMS_CODE."&business=".self::SMS_BUSINESS_KEY."&timestamp=".$timestamp."&validate=".$validate;
        return file_get_contents($requires_url);
	}
}
